#pragma once
#include"BucketHash.h"
namespace xxhhdzl
{
	template<class k,class v,class HashFunction = HashFun<k>>
	class unordered_map
	{
		class keyoft
		{
		public:
			const k& operator()(const pair<const k,v>& value) const
			{
				return value.first;
			}
		};

	public:
		typedef typename BucketHash<k, pair<const k, v>,keyoft, HashFunction>::iterator iterator;
		typedef typename BucketHash<k, pair<const k, v>, keyoft, HashFunction>::const_iterator const_iterator;


		unordered_map()
		{ }

		iterator begin()
		{
			return HashTable.begin();
		}

		const_iterator begin() const
		{
			return HashTable.begin();
		}

		iterator end()
		{
			return HashTable.end();
		}

		const_iterator end() const
		{
			return HashTable.end();
		}

		pair<iterator,bool> insert(const pair<const k, v>& value)
		{
			return HashTable.insert(value);
		}

		iterator find(const k& key)
		{
			return HashTable.find(key);
		}

		bool erase(const k& key)
		{
			return HashTable.erase(key);
		}

		size_t size()
		{
			return HashTable.size();
		}

		v& operator[](const k& key) 
		{
			pair<iterator, bool> ret = HashTable.insert({ key,v() });
			return ret.first->second;
		}

		bool empty()
		{
			return HashTable.empty();
		}

	private:
		BucketHash<k, pair<const k, v>,keyoft,HashFunction> HashTable;
	};
}
